import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;


public class MenuVueControl extends JPanel implements ActionListener{

	private static MenuModel model;
	
	public MenuVueControl(MenuModel model){
		this.model=model;
		this.setLayout(new GridLayout(0, 1));
		for(int i=0;i<model.getOptions().length;i++){
			JButton jbBouton = new JButton(model.getOption(i));
			jbBouton.addActionListener(this);
			this.add(jbBouton);
		}
	}
	
	public void setModel(MenuModel model){
		this.model=model;
	}
	
	@Override
	public void actionPerformed(ActionEvent arg0) {
		JButton jbSource = (JButton)arg0.getSource();
		switch(jbSource.getText()){
			case "Solo" :
				this.removeAll();
				Niveau niveau = new Niveau(model.getFrame());
				this.add(niveau.getJPanel());
				this.revalidate();
				break;
			case "Multijoueurs" :
				System.out.println("A venir");
				break;
			case "Options" : 
				System.out.println("Prochainement");
				break;
			case "Quitter" : 
				if(JOptionPane.showConfirmDialog(this.model.getFrame(), "Voulez-vous vraiment quitter?","Confirmation",JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE)==0) System.exit(0);
		}
		
	}
	
	
}
